package com.meter.data.task;

import com.meter.basic.domain.BasicDevice;
import com.meter.basic.service.IBasicDeviceService;
import com.meter.common.manager.AsyncManager;
import com.meter.data.service.IMeterDataService;
import com.meter.redis.service.RedisService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.util.List;

@Slf4j
@Component("meterTask")
public class MeterTask {

    @Autowired
    private IMeterDataService meterDataService;

    @Autowired
    private IBasicDeviceService basicDeviceService;

    @Autowired
    private RedisService redisService;

    /**
     * 热表数据采集
     * @throws ParseException
     */
    public void meterTask() {
        List<BasicDevice> deviceList = basicDeviceService.list();
        for(BasicDevice basicDevice : deviceList) {
            AsyncManager.me().execute(() -> {
                if (redisService.hHasKey("sys-netty", basicDevice.getDeviceCode())) {
                    meterDataService.readingMeterDataByDevice(basicDevice.getDeviceId(), basicDevice.getDeviceCode(), "定时采集");
                }
            });
        }
    }
}
